package com.wanmait.employment.manageController;

import com.github.pagehelper.PageInfo;
import com.wanmait.employment.entity.Address;
import com.wanmait.employment.entity.Company;
import com.wanmait.employment.mapper.CompanyMapper;
import com.wanmait.employment.service.CompanyService;
import com.wanmait.employment.util.AjaxResult;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/manage/company")
public class CompanyController {
    @Resource
    private CompanyService companyService;

    @GetMapping("getProvince")
    public AjaxResult getProvince(Integer parentId){
        List<Address> provinces=companyService.getProvince(parentId);
        return AjaxResult.success(provinces);
    }

    @GetMapping("list")
    @ResponseBody
    public AjaxResult list1(String companyName, @DateTimeFormat(pattern = "yyyy-MM-dd") Date value1, @DateTimeFormat(pattern = "yyyy-MM-dd") Date value2, Integer pageNum, Integer pageSize) throws ParseException {
        System.out.println(value1+"初始时间");
        System.out.println(value2+"截止时间");
        PageInfo<Company>pageInfo=companyService.findAll(companyName,value1,value2,pageNum,pageSize);
        return AjaxResult.success("",pageInfo);
    }
    @PostMapping("updata")
    public AjaxResult updata(@RequestBody Company company){

        companyService.updata(company);
        return AjaxResult.success("修改成功");
    }
    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        companyService.delete(id);
        return AjaxResult.success("删除成功");
    }
    @GetMapping("resetpasswords")
    public AjaxResult resetpasswords( Integer id){
        String password="123456";
        companyService.resetpasswords(id,password);

        return AjaxResult.success("重置成功");
    }




}
